package com.cain.DontTapTheWhiteTile.tool;

import android.content.res.AssetManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Cain on 2016/6/15.
 * 包含了各种文件的公共操作
 */
public class FileTool {

    private static final String TAG = "FileTool";

    /**
     * 读取assets文件夹下的文件
     * @param fileName
     * @return
     */
    public static String getStringFromAssets(String fileName) {
        try {
            AssetManager manager = MyApplication.getContext().getAssets();
            InputStreamReader inputStreamReader = new InputStreamReader(manager.open(fileName));
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String result = "";
            String line = bufferedReader.readLine();
            while (line != null) {
                result = result + line + "\n";
                line = bufferedReader.readLine();
            }
            bufferedReader.close();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
